package com.thti.mecool.client.model.biz;

import java.util.List;

import android.content.Context;

import com.thti.mecool.client.db.DataBase;
import com.thti.mecool.client.model.po.Communication;
/**
 * 业务bean
 *
 */
public class CommunicationBizImpl {
	private DataBase dataBase;

	public CommunicationBizImpl(Context context) {
		dataBase = new DataBase(context);
	}
	
	public void save(Communication communication){
		String sqlString="insert into communication(userId,projId,projStoreId ,title,type,contactName,contactPosition,contactPhoneOrOther,content ) values(?,?,?,?,?,?,?,?,?)";
		
		dataBase.execObject(sqlString, new String[]{communication.getUserId(),communication.getProjId(),communication.getProjStoreId(),communication.getTitle(),
				communication.getTitle(),communication.getContactName(),communication.getContactPosition(),communication.getContactPhoneOrOther(),communication.getContent()});
		dataBase.close();
	}
	
	public void updateCommId(Communication communication){
		String sqlString="update communication set  communicationId=? where userId=?";
		dataBase.execObject(sqlString, new String[]{communication.getCommunicationId(),communication.getUserId()});
		dataBase.close();
	}
	
	public void delete(int  id ){
		String sql="delete from communication where id=?";
		dataBase.execObject(sql, new String[]{String.valueOf(id)});
		dataBase.close();
	}
	
	@SuppressWarnings("unchecked")
	public List<Communication> findAll(){
		String sql="select * from  communication";
		List<Communication>	list=dataBase.findAll(Communication.class, sql, new String[]{});
		return list;
		
	}
	
}
